<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Lesson extends CI_Controller {
	
	public function index() { }

	public function getLesson($lessonId) {
		$this->load->model('Model_lesson');
		$cursor = $this->Model_lesson->getLesson($lessonId);

		// Conver mongoCursor to JSON
		echo json_encode($cursor);	
	}

	public function getLessonList() {
		$this->load->model('Model_lesson');
		$cursor = $this->Model_lesson->getLessonList();
		echo json_encode(iterator_to_array($cursor));
	}

	public function addLesson() {
		$data = $this->input->post('data');
		if(!$data) {
			echo 'error';
			return;
		}
		$this->load->model('Model_lesson');
		$rs = $this->Model_lesson->addLesson($data);

		print_r($data);
	}

	public function updateLesson() {
		$data = $this->input->post('data');
		$id = $this->input->post('lsId');
		$this->load->model('Model_lesson');
		$rs = $this->Model_lesson->update_lesson($data, $id);
		print_r($data);
	}

}
